<?php
//XML output of an existing MySql database
header("Content-type: text/xml");

require('conn.php');

//to select the database here test is the sample database come with mysql
$db = mysql_select_db("devexDB",$connection)
or die ("Couldn't select database.");

// Build query.
$peakId = $_GET['id'];

$query = "SELECT * FROM peaks WHERE id = $peakId";

$rs = mysql_query($query,$connection)
or die ("invalid query");

//count the no. of  columns in the table
$fcount = mysql_num_fields($rs);

//you can choose any name for the starting tag
echo ("<peaks>");

while($row = mysql_fetch_array( $rs ) ) {
  echo ("<peak>");
  for($i=0; $i< $fcount; $i++) {
    $tag = mysql_field_name( $rs, $i );
    echo ("<$tag>". $row[$i]. "</$tag>");
  }
  echo ("</peak>");
}
echo ("</peaks>");
?>